
#include "SimulateCase.h"

#include <controller/Case.h>

#include <localview/Network.h>
#include <localview/LocalView.h>

#include <evolutive/impl/MesoscopicTrafficSimulation.h>

#include <stdio.h>
#include <iostream>
#include <vector>

using namespace std;

void simulateCase(localview::Network* net, std::string tlsId, int phase) {
    cout << "Simulating case \n";

    FILE* caseOutput = fopen("caseOutput.csv", "w+");

    localview::LocalView lv(tlsId, net);

    MesoscopicTrafficSimulation simulator;

    vector<Case*> caseV;

    Case zeroizedCase;

    caseV.push_back(&zeroizedCase);

    simulator.simulate(caseV, &lv, 200, phase);

    fprintf(caseOutput, "Id, localQueue, sideQueue, nextQueue, nextSideQueue, localGreenExtension, nextExtension, priviousExtension\n");

    for(int i = 0; i < caseV.size(); i++) {
        Case* child = caseV[i];
        fprintf(caseOutput, "%d, %d, %d, %d, %d, %d, %d, %d\n",
                        i,
                        child->getResultLocalQueue(),
                        child->getResultLocalSideQueue(),
                        child->getResultNextQueue(),
                        child->getNextSideQueue(),
                        child->getLocalGreenExtension(),
                        child->getNextGreenExtension(),
                        child->getPreviousGreenExtension());
    }

    fflush(caseOutput);
    fclose(caseOutput);
}
